<%@ Page Language="C#" MasterPageFile="~/quickLMS.master" AutoEventWireup="true" CodeFile="ManageUsers.aspx.cs" Inherits="Admin_ManageUsers" Title="Manage Users" %>
<%@ Register Assembly="Flan.Controls" Namespace="Flan.Controls" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel ID="update1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<br />
Existing Users:
<asp:DropDownList ID="radActive" runat="server" AutoPostBack="True" OnSelectedIndexChanged="radActive_Click">
    <asp:ListItem Value="True" Text="Active" Selected="True"></asp:ListItem>
    <asp:ListItem Value="False" Text="Inactive" ></asp:ListItem>
    <asp:ListItem Value="All" Text="All" ></asp:ListItem>

</asp:DropDownList>
<br />
<br />
    <asp:GridView ID="grdUsers" runat="server" AutoGenerateColumns="False" DataKeyNames="UserID"
     SkinID="ROISkin" OnRowDeleting="grdDeleted" OnRowCommand="grdUsersRowCommand" OnPageIndexChanging="PageChanging" PageSize="10" AllowPaging="true" >
        <Columns>
            <asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkDelete" runat="server" CommandArgument='<%# Eval("UserID") %>' CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this user record?');" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit" HeaderStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkEdit" runat="server" CommandArgument='<%# Eval("UserID") %>' CommandName="Select" Text="Edit"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Assign<br>Courses" HeaderStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkAssign" runat="server" CommandArgument='<%# Eval("UserID") %>' CommandName="Assign" Text="Assign"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Assign<br>Groups" HeaderStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:LinkButton ID="lnkAssignGroups" runat="server" CommandArgument='<%# Eval("UserID") %>' OnCommand="OpenAssignGroups" Text="Assign"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>

        <asp:BoundField DataField="UserName" HeaderText="User Name" HtmlEncode="false" HeaderStyle-HorizontalAlign="Center" />
        <asp:BoundField DataField="Email" HeaderText="Email" HtmlEncode="False" HeaderStyle-HorizontalAlign="Center" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" HtmlEncode="False" HeaderStyle-HorizontalAlign="Center" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" HtmlEncode="False" HeaderStyle-HorizontalAlign="Center" />
        <asp:CheckBoxField DataField="IsLockedOut" HeaderText="Locked Out" HeaderStyle-HorizontalAlign="Center" />
        <asp:CheckBoxField DataField="IsApproved" HeaderText="Approved" HeaderStyle-HorizontalAlign="Center" />
        <asp:BoundField DataField="CreatedOn" HeaderText="Create Date" HtmlEncode="False" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Center" />
    </Columns>

</asp:GridView>
<br />
<asp:LinkButton ID="lnkAddNew" runat="server" Text="Add New"></asp:LinkButton>

<ajax:ModalPopupExtender id="ModalPopup1" runat="server" 
    TargetControlID="lnkAddNew"
    PopupControlID="pnlModal"
    CancelControlID="btnCancel"
    BackgroundCssClass="modalBackground"
    DropShadow="true"

></ajax:ModalPopupExtender>

<asp:panel ID="pnlModal" runat="server" CssClass="modalPopup" >
<asp:Panel ID="pnlDragTitle" runat="server" CssClass="modalHeader">
Add a New User
</asp:Panel>
To add a new user, enter the email of the new user and click "Add User".  The screen will refresh and you will see a list of all users in the system including the newly added user.
<br />
<table>
    <tr>
        <td>First Name:</td>
        <td><asp:TextBox ID="txtFirstname" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Last Name:</td>
        <td><asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Email:</td>
        <td><asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Password:</td>
        <td><asp:TextBox ID="txtPassword1" TextMode="Password" runat="server"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Confirm Password:</td>
        <td><asp:TextBox ID="txtPassword2" TextMode="Password" runat="server"></asp:TextBox><br />
        <asp:CompareValidator ID="valPassword" runat="server" ControlToValidate="txtPassword1" ControlToCompare="txtPassword2" ErrorMessage="Passwords do not match." ></asp:CompareValidator>
        </td>
    </tr>
    <tr runat="server" visible="false">
        <td>Roles:</td>
        <td><asp:CheckBoxList ID="chklstRoles" runat="server" ></asp:CheckBoxList></td>
    </tr>
</table>

<asp:Button ID="btnAddNew" runat="server" OnClick="btnAddNew_Click" Text="Add User" />
<asp:Button ID="btnCancel" runat="server"  Text="Cancel" />
</asp:panel>

</ContentTemplate>
</asp:UpdatePanel>

    <!--------------UpdatePanelPopupExtender-------------------------->
    <cc1:UpdatePanelPopupExtender ID="UpdatePanelPopupExtender2" runat="server" TargetControlID="update2"
        OffsetX="2" OffsetY="2" CalloutColor="#7C6F57" CalloutBorderColor="Black" AutoPostBack="True" 
        OnClose="UpdatePanelPopupExtender2_Close"  />
    <!--------------UpdatePanelPopupExtender-------------------------->
    

<asp:UpdatePanel ID="update2" runat="server">
    <ContentTemplate>
        <asp:Panel ID="pnlEdit" runat="server" CssClass="modalPopup">
            <br />
            Please modify the email of the user and click save changes.
            <br />
            <table>
                <tr>
                    <td>First Name:</td>
                    <td><asp:TextBox ID="txtEditFirstName" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Last Name:</td>
                    <td><asp:TextBox ID="txtEditLastName" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><asp:TextBox ID="txtEditUsername" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><asp:TextBox ID="txtEditPassword1" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>Confirm Password:</td>
                    <td><asp:TextBox ID="txtEditPassword2" runat="server"></asp:TextBox><br />
                    <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="txtEditPassword1" ControlToCompare="txtEditPassword2" ErrorMessage="Passwords do not match." ></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td>Locked Out:</td>
                    <td><asp:CheckBox ID="chlLockedOut" runat="server" /></td>
                </tr>
                <tr>
                    <td>Approved:</td>
                    <td><asp:CheckBox ID="chkApproved" runat="server" /></td>
                </tr>
                <tr runat="server">
                    <td>Roles:</td>
                    <td><asp:CheckBoxList ID="chklstEditRoles" runat="server" ></asp:CheckBoxList></td>
                </tr>
            </table>
            <asp:Button ID="btnSaveEdit" runat="server" Text="Save Changes" OnClick="btnSaveEdit_Click" />
            <asp:Button ID="btnSaveCancel" runat="server" Text="Cancel"  OnClick="btnCancelEdit_Click" />
            
        </asp:Panel>
    
    
    
    </ContentTemplate>
    <triggers>
        <asp:AsyncPostBackTrigger ControlID="grdUsers" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
    </triggers>
</asp:UpdatePanel>


 <!--------------UpdatePanelPopupExtender-------------------------->
    <cc1:UpdatePanelPopupExtender ID="UpdatePanelPopupExtender3" runat="server" TargetControlID="Update3"
        OffsetX="2" OffsetY="2" CalloutColor="#7C6F57" CalloutBorderColor="Black" AutoPostBack="True" 
        OnClose="UpdatePanelPopupExtender2_Close"  />
    <!--------------UpdatePanelPopupExtender-------------------------->
    

<asp:UpdatePanel ID="Update3" runat="server" UpdateMode="Always">
    <ContentTemplate>
    
    

    <asp:HiddenField ID="UserID" runat="server" />
        <asp:Panel ID="Panel1" runat="server" CssClass="modalPopupWide">
        <div style="height: 200px; overflow-y: scroll;">
            <asp:CheckBoxList ID="cblCourses" runat="server" DataValueField="CourseID" DataTextField="CourseName"></asp:CheckBoxList>
            <asp:Button ID="btnSaveCourses" runat="server" OnClick="btnSaveCourses_Click" Text="Save Courses" />
        </div>
        </asp:Panel>
    
    
    
    </ContentTemplate>
</asp:UpdatePanel>

<cc1:UpdatePanelPopupExtender ID="UpdatePanelPopupExtender4" runat="server" TargetControlID="Update4"
        OffsetX="2" OffsetY="2" CalloutColor="#7C6F57" CalloutBorderColor="Black" AutoPostBack="True" 
        OnClose="UpdatePanelPopupExtender4_Close"  />

<asp:UpdatePanel ID="update4" runat="server" UpdateMode="Always">
    <ContentTemplate>
    <asp:Panel ID="Panel2" runat="server" CssClass="modalPopupWide">
    
    <table>
        <tr>
            <td colspan="2">
                Groups:
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:CheckBoxList ID="cblGroups" runat="server" DataTextField="GroupName" DataValueField="GroupID"></asp:CheckBoxList>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="btnAssignGroups" runat="server" Text="Assign Groups" OnClick="AssignGroups" />
            </td>
            <td>
                <asp:Button ID="btnCancelGroups" runat="server" Text="Cancel" OnClick="CancelGroups" />
            </td>
        </tr>
    </table>
    
    </asp:Panel>
    
    
    </ContentTemplate>
</asp:UpdatePanel>

</asp:Content>



